package com.inossem.allotin.fragment;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.inossem.allotin.utils.ACacheUtils;
import com.orhanobut.logger.Logger;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * BaseFragment
 *
 * @author 詹建宇
 * @time on 2018/12/4 20:11
 * @email jianyu.zhan@inossem.com
 */
public abstract class BaseFragment extends Fragment {
    private Unbinder unbinder;
    public Activity mActivity;
    public View view;
    public LayoutInflater inflater;
    public ViewGroup container;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mActivity = (Activity) context;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(initLayout(), container, false);
        unbinder = ButterKnife.bind(this, view);
        this.inflater = inflater;
        this.container = container;
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initData();
        initClick();
        if (ACacheUtils.getShowFakeLayout())
            initFakeLayout();
    }

    @Override
    public void onResume() {
        super.onResume();
        Logger.i("Now Page: Fragment ClassName【" + this.getClass().getName() + "】");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    //==============================================================================================

    /**
     * 设置布局
     *
     * @return layout id
     */
    public abstract int initLayout();

    /**
     * 初始化布局
     */
    public abstract void initView();

    /**
     * 设置数据
     */
    public abstract void initData();

    /**
     * 设置点击事件
     */
    public void initClick() {
    }

    /**
     * 假页面 假逻辑
     */
    public void initFakeLayout() {
    }

}
